/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bayu.services.dao;

import com.bayu.services.entity.Pf;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Bayu
 */
@Repository("pfDao")
@Transactional
public class PfDao {
     private HibernateTemplate hibernateTemplate;

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
	hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    @Transactional(readOnly = false)
    public void save(Pf pf) {
       hibernateTemplate.saveOrUpdate(pf);
    }
    @Transactional(readOnly = false)
    public void delete(Pf pf) {
        hibernateTemplate.delete(pf);
    }
    @Transactional(readOnly = false)
    public void update(Pf pf) {
         hibernateTemplate.update(pf);
    }

    public List<Pf> getAll(String query) {
        return hibernateTemplate.find(query);
    }

    public List<Pf> getAllByDate(String start, String end) {
        return hibernateTemplate.find("from Pf where date between '"+start+"' and '"+end+"' order by date asc");
    }

    public List<Pf> getById(Long id) {
        return hibernateTemplate.find("from Pf where id="+id);
    }

    public List<Pf> getAllByMonth(String month) {
       return hibernateTemplate.find("from Pf where MONTH(date)='"+month+"' order by date asc");
    }

     public List custom(String query){
       return hibernateTemplate.find(query);

    }
}
